#include <boost/asio.hpp>
#include <boost/beast.hpp>
#include <boost/asio/ssl.hpp>
#include <iostream>
#include <string>

using namespace boost::asio;
namespace beast = boost::beast;
namespace ssl = boost::asio::ssl;
int main()
{
    try
    {
        //创建io_context
        io_context ioc;
        //创建ssl上下文
        ssl::context ctx(ssl::context::tlsv12_client);
        //创建ssl套接字
        ssl::stream<ip::tcp::socket> ssl_socket(ioc, ctx);
        //解析服务器地址
        ip::tcp::resolver resolver(ioc);
        auto endpoints = resolver.resolve("www.baidu.com", "https");
        //连接服务器
        connect(ssl_socket.next_layer(), endpoints);
        //配置ssl上下文，加载证书等
        ssl_socket.handshake(ssl::stream_base::client);
        //发送https请求
        std::string request = "GET / HTTP/1.1\r\nHost: www.baidu.com\r\nConnection: close\r\n\r\n";
        boost::asio::write(ssl_socket, boost::asio::buffer(request));
        //读取响应
        boost::asio::streambuf response;
        boost::asio::read_until(ssl_socket, response, "\r\n");


    } catch (std::exception &e) {
        std::cout << "Exception: " << e.what() << "\n";
    }
}
